﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Zxb.DayWork.Logic;
using System.Data;
using System.Xml;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;

namespace Zxb.OneTimeWork
{
    public class CasePicModel
    {
        public int CaseID;
        public int CasePictureTypeID;
        public string CasePictureTypeName;
        public string PicUrl;
        public string SmallPicUrl;
        public int OrderIndex;
        public DateTime AddedTime;
        public int IsValid;

        private CasePicModel()
        {

        }
        public CasePicModel(CasePic pic, int caseid, int orderindex)
        {
            //CasePicModel picmodel = new CasePicModel();
            AddedTime = DateTime.Now;
            CaseID = caseid;
            CasePictureTypeID = pic.CasePictureTypeID;
            CasePictureTypeName = pic.CasePictureTypeName;
            IsValid = 1;
            OrderIndex = orderindex;
            PicUrl = pic.PicUrl;
            SmallPicUrl = pic.SmallPicUrl;
        }
        public static CasePicModel GetRoomPic(string picUrl,int caseid,int posi)
        {
            CasePicModel picmodel = new CasePicModel();
            picmodel.AddedTime = DateTime.Now;
            picmodel.CaseID = caseid;
            picmodel.CasePictureTypeID = 12;
            picmodel.CasePictureTypeName = "户型图";
            picmodel.IsValid = 1;
            picmodel.OrderIndex = posi;
            picmodel.PicUrl = picUrl;
            picmodel.SmallPicUrl = picUrl;
            return picmodel;
        }

        public int InsertDB()
        {
            //Database db = DB.Local;
            //string sql = "insert into [test1].[dbo].[CasesPictures] (CaseID,CasePictureTypeID,CasePictureTypeName,PicUrl,SmallPicUrl,OrderIndex,AddedTime,IsValid) values (@CaseID,@CasePictureTypeID,@CasePictureTypeName,@PicUrl,@SmallPicUrl,@OrderIndex,@AddedTime,@IsValid)";
            Database db = DB.TaskWriter;
            string sql = "insert into [dbo].[CasesPictures] (CaseID,CasePictureTypeID,CasePictureTypeName,PicUrl,SmallPicUrl,OrderIndex,AddedTime,IsValid) values (@CaseID,@CasePictureTypeID,@CasePictureTypeName,@PicUrl,@SmallPicUrl,@OrderIndex,@AddedTime,@IsValid)";
            DbCommand dbCommand = db.GetSqlStringCommand(sql);
            db.AddInParameter(dbCommand, "@CaseID", DbType.Int32, CaseID);
            db.AddInParameter(dbCommand, "@CasePictureTypeID", DbType.Int16, CasePictureTypeID);
            db.AddInParameter(dbCommand, "@CasePictureTypeName", DbType.String, CasePictureTypeName);
            db.AddInParameter(dbCommand, "@PicUrl", DbType.String, PicUrl);
            db.AddInParameter(dbCommand, "@SmallPicUrl", DbType.String, SmallPicUrl);

            db.AddInParameter(dbCommand, "@OrderIndex", DbType.Int32, OrderIndex);
            db.AddInParameter(dbCommand, "@AddedTime", DbType.DateTime, AddedTime);
            db.AddInParameter(dbCommand, "@IsValid", DbType.Int16, IsValid);

            return db.ExecuteNonQuery(dbCommand);
        }
        public static void InsertTest()
        {
            CasePicModel picmodel = new CasePicModel();
            picmodel.AddedTime = DateTime.Now;
            picmodel.CaseID = 123;
            picmodel.CasePictureTypeID = 1;
            picmodel.CasePictureTypeName = "1n";
            picmodel.IsValid = 1;
            picmodel.OrderIndex = 1;
            picmodel.PicUrl = "http";
            picmodel.SmallPicUrl = "s";
            picmodel.InsertDB();
        }
    }
}
